package org.example.comment.interception;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.example.comment.utils.ThreadLocalUtil;
import org.example.constant.MessageConstant;
import org.springframework.stereotype.Component;


/**
 * OpenFeign拦截器
 * 服务发送之前添加信息
 */
@Slf4j
@Component
public class OpenFeignInterception implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        Object object = ThreadLocalUtil.get();
        log.info("进入OpenFeignInterception-用户信息为：{}",object);
        if(object != null){
            requestTemplate.header(MessageConstant.HEADER_NAME, object.toString());
        }
    }
}
